package com.zhaorui.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhaorui.entity.Account;
import com.zhaorui.entity.ZR;
import com.zhaorui.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("account")
@Slf4j
@CrossOrigin
@Api(tags = "登录管理")
public class AccountController {
    @Autowired
    private AccountService accountService;

    /**
     * 用户登录
     * @param account
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录接口")

    public ZR login(@RequestBody Account account){
        log.info ("开始登录{}",account);
        QueryWrapper wrapper=new QueryWrapper ();
        wrapper.eq ("accname",account.getAccname ());
        wrapper.eq ("accpass",account.getAccpass ());
        account = accountService.getOne (wrapper);
        if (account == null) {
            return  new ZR (-1000,"登录失败",null);
        }
        return  new ZR (1000,"登录成功",account);
    }
}
